package com.example.wangzh.developkit.utils.input_filter;

import android.text.InputFilter;
import android.text.Spanned;

/**
 * Created by zhwang16 on 2018/1/2.
 */

public class IdCardInputFilter implements InputFilter {


    @Override
    public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
        if (dstart + source.length() < 18) {
            if (source.toString().matches("^[0-9\\*]*$")) {
                return source;
            } else {
                return "";
            }
        } else {
            CharSequence tempCharSequence = source.subSequence(0, 18 - dstart);
            if (tempCharSequence.toString().endsWith("X") || tempCharSequence.toString().endsWith("x")) {
                return tempCharSequence;
            } else if (tempCharSequence.toString().matches("^[0-9\\*]*$")) {
                return tempCharSequence;
            } else {
                return "";
            }
        }
    }
}
